/* GUI CONVERTED from utindela.p (converter v1.76) Thu May  8 16:08:13 2003 */
/* utindela.p - BUILD PROGRAM TO DELETE UNREFERENCED IN_MSTR RECORDS          */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* REVISION: 7.3      LAST MODIFIED: 04/16/93   BY: pma *G961*                */
/* REVISION: 7.3      LAST MODIFIED: 04/28/95   BY: rwl *G0LN*                */
/* REVISION: 8.5      LAST MODIFIED: 03/29/96   BY: lal *J078*                */
/* REVISION: 8.5      LAST MODIFIED: 08/01/96   BY: *J13J* Markus Barone      */
/* REVISION: 8.5      LAST MODIFIED: 01/13/98   BY: *J28L* Manmohan Pardesi   */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 08/24/99   BY: *N020* Brenda Milton      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KC* Mark Brown         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.6.1.6      BY: Niranjan R.         DATE: 03/15/02  ECO: *P020* */
/* Revision: 1.6.1.7      BY: Robin McCarthy      DATE: 04/05/02  ECO: *P000* */
/* Revision: 1.6.1.8      BY: Jean Miller         DATE: 04/25/02  ECO: *P05M* */
/* Revision: 1.6.1.9.1.1  BY: Russ Witt   DATE: 05/22/02    ECO: *P03G*  */
/* $Revision: 1.6.1.10 $  BY: Russ Witt   DATE: 01/22/03    ECO: *P0M4*  */

/*V8:ConvertMode=Maintenance                                                  */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* I/O     NAME         TYPE        DESCRIPTION                     */
/* -----   ----------   ---------   ------------------------------- */
/* input   inrecno      recid       The record id of in_mstr.       */
/* input   who_called   character   Set this to 'FRM' if audit is   */
/*                                  required. Set this to 'RPT' if  */
/*                                  no audit is required.           */
/* input   table_list   character   A list of table for which       */
/*                                  in_mstr check should not be     */
/*                                  done. e.g "pt_mstr,tr_hist"     */
/* output  filename     character   The tablename that failed the   */
/*                                  in_mstr check.                  */
/* output  yn           logical     The yesno of in_mstr check.     */
/*                                  Yes indicates Pass. No indicates*/
/*                                  Fail.                           */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter inrecno as recid          no-undo.
define input parameter who_called as character   no-undo.
define input parameter table_list as character   no-undo.
define output parameter filename like _file-name no-undo.
define output parameter yn like mfc_logical      no-undo.

define shared variable showdetail like mfc_logical no-undo.

define shared stream prt.

define shared frame indel.

define buffer inmstr for in_mstr.

{utindel.i}

yn = yes.
filename = "".

for each in_mstr where recid(in_mstr) = inrecno:

   if not can-do(table_list, "acm_mstr") then do:
      find first acm_mstr where acm_part = in_part
         and acm_site = in_site no-lock no-error.
      if available acm_mstr then yn = no.
      run show_result("acm_mstr", yn).
      if not yn then leave.
   end. /* acm_mstr */

   if not can-do(table_list, "atp_det") then do:
      find first atp_det where atp_part = in_part
         and atp_site = in_site no-lock no-error.
      if available atp_det then yn = no.
      run show_result("atp_det", yn).
      if not yn then leave.
   end. /* atp_det  */

   if not can-do(table_list, "ca_mstr") then do:
      find first ca_mstr where ca_part = in_part
         and ca_site = in_site no-lock no-error.
      if available ca_mstr then yn = no.
      run show_result("ca_mstr", yn).
      if not yn then leave.
   end. /* ca_mstr */

   if not can-do(table_list, "chm_mstr") then do:
      find first chm_mstr where chm_part = in_part
         and chm_site = in_site no-lock no-error.
      if available chm_mstr then yn = no.
      run show_result("chm_mstr", yn).
      if not yn then leave.
   end. /* chm_mstr */
   
   if not can-do(table_list, "cph_hist") then do:
      find first cph_hist where cph_part = in_part
         and cph_site = in_site use-index cph_part no-lock no-error.
      if available cph_hist then yn = no.
      run show_result("cph_hist", yn).
      if not yn then leave.
   end. /* cph_hist */

   if not can-do(table_list, "dsd_det") then do:
      find first dsd_det where dsd_part = in_part
         and dsd_site = in_site no-lock no-error.
      if available dsd_det then yn = no.
      run show_result("dsd_det", yn).
      if not yn then leave.
   end. /* dsd_det  */

   if not can-do(table_list, "dsr_mstr") then do:
      find first dsr_mstr where dsr_part = in_part
         and dsr_site = in_site no-lock no-error.
      if available dsr_mstr then yn = no.
      run show_result("dsr_mstr", yn).
      if not yn then leave.
   end. /* dsr_mstr */

   if not can-do(table_list, "ds_det") then do:
      find first ds_det where ds_part = in_part
         and ds_site = in_site no-lock no-error.
      if available ds_det then yn = no.
      run show_result("ds_det", yn).
      if not yn then leave.
   end. /* ds_det   */

   if not can-do(table_list, "ers_mstr") then do:
      find first ers_mstr where ers_part = in_part
         and ers_site = in_site no-lock no-error.
      if available ers_mstr then yn = no.
      run show_result("ers_mstr", yn).
      if not yn then leave.
   end. /* ers_mstr */

   if not can-do(table_list, "fcs_sum") then do:
      find first fcs_sum where fcs_part = in_part
         and fcs_site = in_site no-lock no-error.
      if available fcs_sum then yn = no.
      run show_result("fcs_sum", yn).
      if not yn then leave.
   end. /* fcs_sum  */

   if not can-do(table_list, "fc_det") then do:
      find first fc_det where fc_part = in_part
         and fc_site = in_site no-lock no-error.
      if available fc_det then yn = no.
      run show_result("fc_det", yn).
      if not yn then leave.
   end. /* fc_det  */

   if not can-do(table_list, "ff_mstr") then do:
      find first ff_mstr where ff_part = in_part
         and ff_site = in_site no-lock no-error.
      if available ff_mstr then yn = no.
      run show_result("ff_mstr", yn).
      if not yn then leave.
   end. /* ff_mstr */

   if not can-do(table_list, "fh_mstr") then do:
      find first fh_mstr where
         (fh_parent = in_part or fh_comp = in_part)
         and fh_site = in_site no-lock no-error.
      if available fh_mstr then yn = no.
      run show_result("fh_mstr", yn).
      if not yn then leave.
   end. /* fh_mstr */

   if not can-do(table_list, "fkt_mstr") then do:
      find first fkt_mstr where fkt_part = in_part
         and fkt_site = in_site no-lock no-error.
      if available fkt_mstr then yn = no.
      run show_result("fkt_mstr", yn).
      if not yn then leave.
   end. /* fkt_mstr */

   if not can-do(table_list, "flp_plan") then do:
      find first flp_plan where flp_part = in_part
         and flp_site = in_site no-lock no-error.
      if available flp_plan then yn = no.
      run show_result("flp_plan", yn).
      if not yn then leave.
   end. /* flp_plan */

   if not can-do(table_list, "fpd_cost") then do:
      find first fpd_cost where fpd_part = in_part
         and fpd_site = in_site no-lock no-error.
      if available fpd_cost then yn = no.
      run show_result("fpd_cost", yn).
      if not yn then leave.
   end. /* fpd_cost */

   if not can-do(table_list, "fp1_plan") then do:
      find first fp1_plan where fp1_part = in_part
         and fp1_site = in_site no-lock no-error.
      if available fp1_plan then yn = no.
      run show_result("fp1_plan", yn).
      if not yn then leave.
   end. /* fp1_plan */

   if not can-do(table_list, "fp2_plan") then do:
      find first fp2_plan where fp2_part = in_part
         and fp2_site = in_site no-lock no-error.
      if available fp2_plan then yn = no.
      run show_result("fp2_plan", yn).
      if not yn then leave.
   end. /* fp2_plan */

   if not can-do(table_list, "fp3_plan") then do:
      find first fp3_plan where fp3_part = in_part
         and fp3_site = in_site no-lock no-error.
      if available fp3_plan then yn = no.
      run show_result("fp3_plan", yn).
      if not yn then leave.
   end. /* fp3_plan */

   if not can-do(table_list, "fsd_det") then do:
      find first fsd_det where fsd_part = in_part
         and fsd_site = in_site no-lock no-error.
      if available fsd_det then yn = no.
      run show_result("fsd_det", yn).
      if not yn then leave.
   end. /* fsd_det  */

   if not can-do(table_list, "fslp_pln") then do:
      find first fslp_pln where fslp_part = in_part
         and fslp_site = in_site no-lock no-error.
      if available fslp_pln then yn = no.
      run show_result("fslp_pln", yn).
      if not yn then leave.
   end. /* fslp_pln */

   if not can-do(table_list, "fsp1_pln") then do:
      find first fsp1_pln where fsp1_part = in_part
         and fsp1_site = in_site no-lock no-error.
      if available fsp1_pln then yn = no.
      run show_result("fsp1_pln", yn).
      if not yn then leave.
   end. /* fsp1_pln */

   if not can-do(table_list, "fsp2_pln") then do:
      find first fsp2_pln where fsp2_part = in_part
         and fsp2_site = in_site no-lock no-error.
      if available fsp2_pln then yn = no.
      run show_result("fsp2_pln", yn).
      if not yn then leave.
   end. /* fsp2_pln */

   if not can-do(table_list, "fsp3_pln") then do:
      find first fsp3_pln where fsp3_part = in_part
         and fsp3_site = in_site no-lock no-error.
      if available fsp3_pln then yn = no.
      run show_result("fsp3_pln", yn).
      if not yn then leave.
   end. /* fsp3_pln */

   if not can-do(table_list, "ibh_hist") then do:
      find first ibh_hist where ibh_part = in_part
         and ibh_site = in_site no-lock no-error.
      if available ibh_hist then yn = no.
      run show_result("ibh_hist", yn).
      if not yn then leave.
   end. /* ibh_hist */

   if not can-do(table_list, "idh_hist") then do:
      find first idh_hist where idh_part = in_part
         and idh_site = in_site use-index idh_part no-lock no-error.
      if available idh_hist then yn = no.
      run show_result("idh_hist", yn).
      if not yn then leave.
   end. /* idh_hist */

   if not can-do(table_list, "ieh_hist") then do:
      find first ieh_hist where ieh_part = in_part
         and ieh_site = in_site no-lock no-error.
      if available ieh_hist then yn = no.
      run show_result("ieh_hist", yn).
      if not yn then leave.
   end. /* ieh_hist */

   if not can-do(table_list, "ild_det") then do:
      find first ild_det where ild_part = in_part
         and ild_site = in_site no-lock no-error.
      if available ild_det then yn = no.
      run show_result("ild_det", yn).
      if not yn then leave.
   end. /* ild_det  */

   if not can-do(table_list, "ind_det") then do:
      find first ind_det where ind_part = in_part
         and ind_site = in_site no-lock no-error.
      if available ind_det then yn = no.
      run show_result("ind_det", yn).
      if not yn then leave.
   end. /* ind_det  */

   if not can-do(table_list, "iro_det") then do:
      find first iro_det where iro_part = in_part
         and iro_site = in_site no-lock no-error.
      if available iro_det then yn = no.
      run show_result("iro_det", yn).
      if not yn then leave.
   end. /* iro_det  */

   if not can-do(table_list, "itmh_hist") then do:
      find first itmh_hist where itmh_part = in_part
         and itmh_site = in_site no-lock no-error.
      if available itmh_hist then yn = no.
      run show_result("itmh_hist", yn).
      if not yn then leave.
   end. /* itmh_hist */

   if not can-do(table_list, "itm_det") then do:
      find first itm_det where itm_part = in_part
         and itm_site = in_site no-lock no-error.
      if available itm_det then yn = no.
      run show_result("itm_det", yn).
      if not yn then leave.
   end. /* itm_det  */

   if not can-do(table_list, "itsd_det") then do:
      find first itsd_det where itsd_part = in_part
         and itsd_site = in_site no-lock no-error.
      if available itsd_det then yn = no.
      run show_result("itsd_det", yn).
      if not yn then leave.
   end. /* itsd_det */

   if not can-do(table_list, "its_mstr") then do:
      find first its_mstr where its_part = in_part
         and its_site = in_site no-lock no-error.
      if available its_mstr then yn = no.
      run show_result("its_mstr", yn).
      if not yn then leave.
   end. /* its_mstr */

   if not can-do(table_list, "knbi_mstr") then do:
      for each knbi_mstr
      fields(knbi_part
             knbi_keyid)
      where knbi_part = in_part
      no-lock,
      each knb_mstr
      fields(knb_keyid
             knb_knbsm_keyid)
      where knb_knbi_keyid = knbi_keyid
      no-lock,
      each knbsm_mstr
      fields(knbsm_keyid
             knbsm_site)
      where knbsm_keyid = knb_knbsm_keyid
      and   knbsm_site  = in_site
      no-lock:
          yn = no.
      end.
      run show_result("knbi_mstr", yn).
      if not yn then leave.
   end. /* knbi_mstr */


   if not can-do(table_list, "lnd_det") then do:
      find first lnd_det where lnd_part = in_part
         and lnd_site = in_site no-lock no-error.
      if available lnd_det then yn = no.
      run show_result("lnd_det", yn).
      if not yn then leave.
   end. /* lnd_det */

   if not can-do(table_list, "mps_mstr") then do:
      find first mps_mstr where mps_part = in_part
         and mps_site = in_site no-lock no-error.
      if available mps_mstr then yn = no.
      run show_result("mps_mstr", yn).
      if not yn then leave.
   end. /* mps_mstr */

   if not can-do(table_list, "mrp_det") then do:
      find first mrp_det where mrp_part = in_part
         and mrp_site = in_site use-index mrp_sitetype no-lock no-error.
      if available mrp_det then yn = no.
      run show_result("mrp_det", yn).
      if not yn then leave.
   end. /* mrp_det  */

   if not can-do(table_list, "oa_det") then do:
      find first oa_det where oa_part = in_part
         and oa_site = in_site no-lock no-error.
      if available oa_det then yn = no.
      run show_result("oa_det", yn).
      if not yn then leave.
   end. /* oa_det   */

   if not can-do(table_list, "op_hist") then do:
      find first op_hist where op_part = in_part
         and op_site = in_site use-index op_part no-lock no-error.
      if available op_hist then yn = no.
      run show_result("op_hist", yn).
      if not yn then leave.
   end. /* op_hist  */

   if not can-do(table_list, "pfc_det") then do:
      find first pfc_det where pfc_peg_part = in_part
         and pfc_site = in_site no-lock no-error.
      if available pfc_det then yn = no.
      run show_result("pfc_det", yn).
      if not yn then leave.
   end. /* pfc_det  */

   if not can-do(table_list, "pfd_det") then do:
      find first pfd_det where pfd_part = in_part
         and pfd_site = in_site no-lock no-error.
      if available pfd_det then yn = no.
      run show_result("pfd_det", yn).
      if not yn then leave.
   end. /* pfd_det  */

   if not can-do(table_list, "pod_det") then do:
      find first pod_det where pod_part = in_part
         and pod_site = in_site no-lock no-error.
      if available pod_det then yn = no.
      run show_result("pod_det", yn).
      if not yn then leave.
   end. /* pod_det  */

   if not can-do(table_list, "prh_hist") then do:
      find first prh_hist where prh_part = in_part
         and prh_site = in_site no-lock no-error.
      if available prh_hist then yn = no.
      run show_result("prh_hist", yn).
      if not yn then leave.
   end. /* prh_hist */

   if not can-do(table_list, "ptp_det") then do:
      find first ptp_det where ptp_part = in_part
         and ptp_site = in_site no-lock no-error.
      if available ptp_det then yn = no.
      run show_result("ptp_det", yn).
      if not yn then leave.
   end. /* ptp_det  */

   if not can-do(table_list, "ptr_det") then do:
      find first ptr_det where ptr_part = in_part
         and ptr_site = in_site no-lock no-error.
      if available ptr_det then yn = no.
      run show_result("ptr_det", yn).
      if not yn then leave.
   end. /* ptr_det  */

   if not can-do(table_list, "pt_mstr") then do:
      find first pt_mstr where pt_part = in_part
         and pt_site = in_site no-lock no-error.
      if available pt_mstr then yn = no.
      run show_result("pt_mstr", yn).
      if not yn then leave.
   end. /* pt_mstr */

   if not can-do(table_list, "qc_mstr") then do:
      find first qc_mstr where qc_part = in_part
         and qc_site = in_site use-index qc_part no-lock no-error.
      if available qc_mstr then yn = no.
      run show_result("qc_mstr", yn).
      if not yn then leave.
   end. /* qc_mstr */

   if not can-do(table_list, "qod_det") then do:
      find first qod_det where qod_part = in_part
         and qod_site = in_site no-lock no-error.
      if available qod_det then yn = no.
      run show_result("qod_det", yn).
      if not yn then leave.
   end. /* qod_det  */

   if not can-do(table_list, "rdf_mstr") then do:
      find first rdf_mstr where rdf_part = in_part
         and rdf_transit_site = in_site no-lock no-error.
      if available rdf_mstr then yn = no.
      run show_result("rdf_mstr", yn).
      if not yn then leave.
   end. /* rdf_mstr */

   if not can-do(table_list, "req_det") then do:
      find first req_det where req_part = in_part
         and req_site = in_site no-lock no-error.
      if available req_det then yn = no.
      run show_result("req_det", yn).
      if not yn then leave.
   end. /* req_det */

   if not can-do(table_list, "rhd_hist") then do:
      find first rhd_hist where rhd_par_part = in_part
         and rhd_site = in_site no-lock no-error.
      if available rhd_hist then yn = no.
      run show_result("rhd_hist", yn).
      if not yn then leave.
   end. /* rhd_hist */

   if not can-do(table_list, "rmd_det") then do:
      find first rmd_det where rmd_par_part = in_part
         and rmd_site = in_site no-lock no-error.
      if available rmd_det then yn = no.
      run show_result("rmd_det", yn).
      if not yn then leave.
   end. /* rmd_det  */

   if not can-do(table_list, "rps_mstr") then do:
      find first rps_mstr where rps_part = in_part
         and rps_site = in_site no-lock no-error.
      if available rps_mstr then yn = no.
      run show_result("rps_mstr", yn).
      if not yn then leave.
   end. /* rps_mstr */

   if not can-do(table_list, "rq_mstr") then do:
      find first rq_mstr where rq_part = in_part
         and rq_site = in_site no-lock no-error.
      if available rq_mstr then yn = no.
      run show_result("rq_mstr", yn).
      if not yn then leave.
   end. /* rq_mstr */

   if not can-do(table_list, "sadh_hist") then do:
      find first sadh_hist where sadh_part = in_part
         and sadh_site = in_site no-lock no-error.
      if available sadh_hist then yn = no.
      run show_result("sadh_hist", yn).
      if not yn then leave.
   end. /* sadh_hist */

   if not can-do(table_list, "sad_det") then do:

      find first sad_det where sad_for  = in_part
         and sad_site = in_site no-lock no-error.
      if available sad_det then yn = no.
      run show_result("sad_det", yn).
      if not yn then leave.
   end. /* sad_det  */

   if not can-do(table_list, "sah_hist") then do:
      find first sah_hist where sah_part = in_part
         and sah_site = in_site no-lock no-error.
      if available sah_hist then yn = no.
      run show_result("sah_hist", yn).
      if not yn then leave.
   end. /* sah_hist */
   /* Sa_part WAS NEVER pt_mstr FIELD. THERE WON'T BE ANY in_mstr */
   /* RECORDS FOR sa_part. */

   /* CANNOT DELETE IF THIS in_mstr IS A SOURCE COST SITE FOR        */
   /* ANOTHER in_mstr'S GL COSTS.                                    */
   /* THE in_mstr TABLE IS THE INDICATOR OF THIS EVENT. BUT THE      */
   /* FAILURE IS ON THE sct_det, AS THAT IS THE SHARED COST RECORD.  */
   if not can-do(table_list, "in_mstr") then do:
      if can-find(first inmstr where inmstr.in_part = in_mstr.in_part
      and inmstr.in_gl_cost_site = in_mstr.in_site
      and recid(inmstr) <> inrecno) then yn = no.

      run show_result("sct_det", yn).
      if not yn then leave.
   end. /* inmstr */

   if not can-do(table_list, "seq_mstr") then do:
      find first seq_mstr where seq_part = in_part
         and seq_site = in_site no-lock no-error.
      if available seq_mstr then yn = no.
      run show_result("seq_mstr", yn).
      if not yn then leave.
   end. /* seq_mstr */

   if not can-do(table_list, "sm_mstr") then do:
      find first sm_mstr where sm_part = in_part
         and (sm_sup_site = in_site or sm_mktg_site = in_site)
      no-lock no-error.
      if available sm_mstr then yn = no.
      run show_result("sm_mstr", yn).
      if not yn then leave.
   end. /* sm_mstr */

   if not can-do(table_list, "sob_det") then do:
      find first sob_det where sob_part = in_part
         and sob_site = in_site no-lock no-error.
      if available sob_det then yn = no.
      run show_result("sob_det", yn).
      if not yn then leave.
   end. /* sob_det  */

   if not can-do(table_list, "sod_det") then do:
      find first sod_det where sod_part = in_part
         and sod_site = in_site no-lock no-error.
      if available sod_det then yn = no.
      run show_result("sod_det", yn).
      if not yn then leave.
   end. /* sod_det  */

   if not can-do(table_list, "tag_mstr") then do:
      find first tag_mstr where tag_part = in_part
         and tag_site = in_site no-lock no-error.
      if available tag_mstr then yn = no.
      run show_result("tag_mstr", yn).
      if not yn then leave.
   end. /* tag_mstr */

   if not can-do(table_list, "tr_hist") then do:
      find first tr_hist where tr_part = in_part
         and tr_site = in_site and tr_type <> "CST-ADJ" use-index tr_part_eff no-lock no-error.
      if available tr_hist then yn = no.
      run show_result("tr_hist", yn).
      if not yn then leave.
   end. /* tr_hist */

   if not can-do(table_list, "wod_det") then do:
      find first wod_det where wod_part = in_part
         and wod_site = in_site no-lock no-error.
      if available wod_det then yn = no.
      run show_result("wod_det", yn).
      if not yn then leave.
   end. /* wod_det  */

   if not can-do(table_list, "wo_mstr") then do:
      find first wo_mstr where wo_part = in_part
         and wo_site = in_site no-lock no-error.
      if available wo_mstr then yn = no.
      run show_result("wo_mstr", yn).
      if not yn then leave.
   end. /* wo_mstr  */

end. /* FOR EACH in_mstr */

PROCEDURE show_result:

   define input parameter fn like _file-name no-undo.
   define input parameter yesno like mfc_logical no-undo.

   if who_called = 'FRM' and (showdetail or yesno = no) then do with frame indel:
      display stream prt
         fn @ filename
         yesno @ yn.
      down stream prt 1.
   end. /* IF who_called  = 'FRM' */

   if not yesno then filename = fn.

END PROCEDURE.
